home *** CD-ROM | disk | FTP | other *** search
/ Gurewich OLE Controls for Visual Basic 4 / Gurewich OLE Controls for Visual Basic 4.iso / ocxprog / programs / ch14 / spy.frm (.txt) next >
Encoding:
Visual Basic Form  |  1995-08-24  |  8.4 KB  |  248 lines

  1. VERSION 4.00
  2. Begin VB.Form frmSpy 
  3.    Caption         =   "The Spy Program"
  4.    ClientHeight    =   5910
  5.    ClientLeft      =   1215
  6.    ClientTop       =   945
  7.    ClientWidth     =   5325
  8.    Height          =   6600
  9.    Icon            =   "SPY.frx":0000
  10.    Left            =   1155
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    ScaleHeight     =   5910
  14.    ScaleWidth      =   5325
  15.    Top             =   315
  16.    Width           =   5445
  17.    Begin VB.CheckBox chkReplaceKeyboardHits 
  18.       Caption         =   "Replace keyboard hits in Paintbrush with the letters: SPY SPY SPY..."
  19.       Height          =   255
  20.       Left            =   120
  21.       TabIndex        =   6
  22.       Top             =   5520
  23.       Width           =   5295
  24.    End
  25.    Begin VB.CheckBox chkBeep 
  26.       Caption         =   "Beep whenever someone double-clicks in Paintbrush"
  27.       Height          =   255
  28.       Left            =   120
  29.       TabIndex        =   5
  30.       Top             =   5160
  31.       Width           =   4215
  32.    End
  33.    Begin VB.Frame Frame1 
  34.       Caption         =   "Messages"
  35.       Height          =   615
  36.       Left            =   120
  37.       TabIndex        =   2
  38.       Top             =   4320
  39.       Width           =   3975
  40.       Begin VB.OptionButton optAllMessages 
  41.          Caption         =   "All &Messages"
  42.          Height          =   320
  43.          Left            =   120
  44.          TabIndex        =   4
  45.          Top             =   240
  46.          Value           =   -1  'True
  47.          Width           =   1225
  48.       End
  49.       Begin VB.OptionButton optOnlyDoubleClick 
  50.          Caption         =   "Only &Double-Click Message"
  51.          Height          =   320
  52.          Left            =   1560
  53.          TabIndex        =   3
  54.          Top             =   240
  55.          Width           =   2295
  56.       End
  57.    End
  58.    Begin VB.Timer Timer1 
  59.       Interval        =   200
  60.       Left            =   4440
  61.       Top             =   5040
  62.    End
  63.    Begin VB.TextBox txtMsg 
  64.       BeginProperty Font 
  65.          name            =   "Courier"
  66.          charset         =   0
  67.          weight          =   400
  68.          size            =   9.75
  69.          underline       =   0   'False
  70.          italic          =   0   'False
  71.          strikethrough   =   0   'False
  72.       EndProperty
  73.       Height          =   4095
  74.       Left            =   120
  75.       MultiLine       =   -1  'True
  76.       TabIndex        =   1
  77.       Top             =   120
  78.       Width           =   5055
  79.    End
  80.    Begin TegspyLib.TegoSpy TegoSpy1 
  81.       Height          =   600
  82.       Left            =   4200
  83.       TabIndex        =   0
  84.       Top             =   4320
  85.       Width           =   930
  86.       _version        =   65536
  87.       _extentx        =   1640
  88.       _extenty        =   1058
  89.       _stockprops     =   0
  90.    End
  91.    Begin VB.Menu mnuFile 
  92.       Caption         =   "&File"
  93.       Begin VB.Menu mnuExit 
  94.          Caption         =   "E&xit"
  95.       End
  96.    End
  97.    Begin VB.Menu mnuHelp 
  98.       Caption         =   "&Help"
  99.       Begin VB.Menu mnuAbout 
  100.          Caption         =   "&About..."
  101.       End
  102.    End
  103. Attribute VB_Name = "frmSpy"
  104. Attribute VB_Creatable = False
  105. Attribute VB_Exposed = False
  106. ' All variables must be declared.
  107. Option Explicit
  108. ' Declare general variables.
  109. Dim gMsg As String
  110. Private Sub Form_Load()
  111. TegoSpy1.Visible = False
  112. End Sub
  113. Private Sub mnuAbout_Click()
  114.    Dim Title
  115.    Dim Msg
  116.    Dim CR
  117.    CR = Chr(13) + Chr(10)
  118.    ' The title of the About message box.
  119.    Title = "About the Spy Program"
  120.    ' Prepare the message of the About message box.
  121.    Msg = "This program was written with Visual "
  122.    Msg = Msg + "Basic for Windows, using the "
  123.    Msg = Msg + "TegoSoft Spy OCX control. "
  124.    Msg = Msg + CR + CR
  125.    Msg = Msg + "The TegoSoft Spy OCX control "
  126.    Msg = Msg + "is part of the TegoSoft OCX Control "
  127.    Msg = Msg + "Kit - a collection of various OCX controls. "
  128.    Msg = Msg + CR + CR
  129.    Msg = Msg + "For more information about the "
  130.    Msg = Msg + "TegoSoft OCX Control Kit, contact TegoSoft "
  131.    Msg = Msg + "at:"
  132.    Msg = Msg + CR + CR
  133.    Msg = Msg + "TegoSoft Inc." + CR
  134.    Msg = Msg + "P.O. Box 389" + CR
  135.    Msg = Msg + "Bellmore, NY 11710"
  136.    Msg = Msg + CR + CR
  137.    Msg = Msg + "Phone: (516)783-4824"
  138.    ' Display the About message box.
  139.    MsgBox Msg, vbInformation, Title
  140. End Sub
  141. Private Sub mnuExit_Click()
  142.   ' Terminate the program.
  143.   Unload Me
  144. End Sub
  145. Private Sub TegoSpy1_MessageTrap()
  146. ' NOTE:
  147. ' This event procedure traps messagges that Windows
  148. ' sends to the currently running programs.
  149. ' Before a message is sent to the program that
  150. ' owns the message, this event procedure is
  151. ' executed.
  152. ' You can write code that analyzes the message
  153. ' and intercepts the message. That is, you can
  154. ' change the content of the message. For example,
  155. ' the sample code below, intercepts keyboard
  156. ' messages that are sent to Paintbrush, so that
  157. ' Paintbrush will always type the letters "S","P",
  158. ' "Y", whenever the user types anything in
  159. ' Paintbrush.
  160. ' Do NOT write code in this procedure that
  161. ' generates messages! For example, you must NOT
  162. ' write code in this procedure that changes the
  163. ' Caption or Text properties of the screen, of label controls, of Text
  164. ' controls or of any other controls. If you write
  165. ' code that generates messages in this procedure,
  166. ' then the system will be overloaded with messages.
  167. ' If you need to write code that displays text in
  168. ' this procedure, you can do it as follows:
  169. ' 1. Declare a general string variable in the
  170. '    General Declarations section of the form.
  171. ' 2. In this procedure, update the general string
  172. '    variable with the text that you want to display.
  173. ' 3. Place a timer control inside the form.
  174. ' 4. Attach code to the Timer event of the timer
  175. '    control that assigns the value of the general
  176. '    string variable to the Text property of the
  177. '    TextBox control.
  178. ' For example, this program uses a general string
  179. ' variable called gMsg. The code below assigns text
  180. ' to the gMsg variable. And the code inside the
  181. ' Timer1_Timer() procedure assigns the value of
  182. ' gMsg to the Text property of the txtMsg TextBox
  183. ' control.
  184. Dim ProgramName As String
  185. Dim ProgramIsPaintbrush As Boolean
  186. Static NumMessages As Integer
  187. Static CurrentLetter As String
  188. ' Get the Program name of the message.
  189. ProgramName = TegoSpy1.msgProgramWindowTitle
  190. ' Is the program name Paintbrush?
  191. If Left(ProgramName, 5) = "Paint" Or _
  192.             Right(ProgramName, 5) = "Paint" Then
  193.    ProgramIsPaintbrush = True
  194.    ProgramIsPaintbrush = False
  195. End If
  196. ' If the Only Double-Click radio button is selected,
  197. ' or the message is Double-Click, we want to display
  198. ' the message. Otherwise, we don't want to display
  199. ' the message.
  200. If optOnlydoubleclick.Value = False Or _
  201.                TegoSpy1.msgMessage = 515 Then
  202.    ' Display the name of the program and the message.
  203.    gMsg = gMsg + Left(ProgramName, 30)
  204.    gMsg = gMsg + " - "
  205.    gMsg = gMsg + Str(TegoSpy1.msgMessage)
  206.    gMsg = gMsg + Chr(13) + Chr(10)
  207.    ' Increment the NumMessages counter.
  208.    NumMessages = NumMessages + 1
  209.    ' If 20 messages are displayed, clear the messages
  210.    ' text box, and reset NumMessages to 0.
  211.    If NumMessages > 20 Then
  212.       gMsg = ""
  213.       NumMessages = 0
  214.    End If
  215. End If
  216. ' If the chkBeep check box is checked,
  217. ' and the program name is Paintbrush, and the
  218. ' message is Double-Click, beep.
  219. If chkBeep.Value = 1 And _
  220.        ProgramIsPaintbrush = True And _
  221.        TegoSpy1.msgMessage = 515 Then
  222.    Beep
  223. End If
  224. ' If the chkReplaceKeyboardHits check box
  225. ' is checked, and the program name is
  226. ' Paintbrush, and the user pressed any key on
  227. ' the keyboard, replace the ascii code of
  228. ' the pressed key with the letters "S", "P", "Y".
  229. If chkReplaceKeyboardHits.Value = 1 And _
  230.          ProgramIsPaintbrush = True And _
  231.          TegoSpy1.msgMessage = 258 Then
  232.    If CurrentLetter = "S" Then
  233.       CurrentLetter = "P"
  234.    ElseIf CurrentLetter = "P" Then
  235.       CurrentLetter = "Y"
  236.    ElseIf CurrentLetter = "Y" Then
  237.       CurrentLetter = " "
  238.    Else
  239.       CurrentLetter = "S"
  240.    End If
  241.    TegoSpy1.msgWParam = Asc(CurrentLetter)
  242. End If
  243. End Sub
  244. Private Sub Timer1_Timer()
  245. ' Update the txtMsg text box.
  246. txtMsg.Text = gMsg
  247. End Sub
  248.